package com.niiwoo.civet.account.service.local.check.job.apiservice.commission;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.niiwoo.civet.account.dao.entity.AccountBase;
import com.niiwoo.civet.account.dao.entity.AccountCheckingCommission;
import com.niiwoo.civet.account.dao.entity.AccountCheckingException;
import com.niiwoo.civet.account.dao.entity.AccountCheckingInvestOrder;
import com.niiwoo.civet.account.dao.entity.BatchTransOrderDetail;
import com.niiwoo.civet.account.dao.entity.BatchTransOrderDetailBiz;
import com.niiwoo.civet.account.dao.entity.RechargeOrder;
import com.niiwoo.civet.account.dao.entity.RollbackRechargeOrder;
import com.niiwoo.civet.account.dao.entity.WithdrawConfirmOrder;
import com.niiwoo.civet.account.dao.entity.WithdrawOrder;
import com.niiwoo.civet.account.dao.mapper.AccountCheckingBatchTransOrderDetailBizMapperExt;
import com.niiwoo.civet.account.dao.mapper.AccountCheckingCommissionMapperExt;
import com.niiwoo.civet.account.dao.mapper.AccountCheckingRollbackRechargeOrderMapperExt;
import com.niiwoo.civet.account.dao.mapper.AccountCheckingWithdrawConfirmOrderMapperExt;
import com.niiwoo.civet.account.dao.mapper.RechargeOrderMapperExt;
import com.niiwoo.civet.account.dao.mapper.RollbackRechargeOrderMapper;
import com.niiwoo.civet.account.dao.mapper.RollbackRechargeOrderMapperExt;
import com.niiwoo.civet.account.dao.mapper.WithdrawOrderMapperExt;
import com.niiwoo.civet.account.dao.mapper.AccountBaseMapperExt;
import com.niiwoo.civet.account.dao.mapper.AccountCheckingInvestOrderMapper;
import com.niiwoo.civet.account.dao.mapper.BatchTransOrderDetailBizMapperExt;
import com.niiwoo.civet.account.dao.mapper.BatchTransOrderDetailMapperExt;
import com.niiwoo.civet.account.service.CreditorTransferDubboService;
import com.niiwoo.civet.trade.dto.common.LendOrderDetailBizDTO;
import com.niiwoo.civet.trade.dto.common.LendOrderDetailDTO;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorTransferConfirmOrderDetailBizDTO;
import com.niiwoo.civet.trade.dto.response.creditor.CreditorTransferConfirmOrderDetailDTO;
import com.niiwoo.civet.trade.dto.response.newRefund.RefundOrderDetailBizResponseDTO;
import com.niiwoo.civet.trade.service.creditor.CreditorTransferConfirmDubboService;
import com.niiwoo.civet.trade.service.lend.ProjectLendDetailDubboService;
import com.niiwoo.civet.trade.service.newRefund.RefundOrderDetailBizDubboService;
import com.niiwoo.tripod.lanmao.enums.BusinessTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.dangdang.ddframe.rdb.sharding.api.HintManager;
import com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder;
import com.niiwoo.civet.account.dto.request.AccountCheckingCommissionRequestDTO;
import com.niiwoo.civet.account.service.local.check.job.api.CheckDetailService;
import com.niiwoo.civet.account.service.local.check.job.api.ParseService;
import com.niiwoo.civet.account.service.local.check.job.enums.CheckResultEnum;
import com.niiwoo.civet.account.service.local.check.job.enums.HandleTypeEnum;
import com.niiwoo.civet.account.service.local.check.job.util.DateUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service(version = "1.0.0")
public class CommissionCheckDetailServiceImpl implements CheckDetailService<AccountCheckingCommission>,ParseService<AccountCheckingCommission> {

    @Autowired
    private AccountCheckingCommissionMapperExt accountCheckingCommissionMapperExt;
    @Autowired
    private WithdrawOrderMapperExt withdrawOrderMapperExt;
    @Autowired
    private AccountCheckingWithdrawConfirmOrderMapperExt accountCheckingWithdrawConfirmOrderMapperExt;
    @Autowired
    private RechargeOrderMapperExt rechargeOrderMapperExt;
    @Autowired
    private AccountCheckingBatchTransOrderDetailBizMapperExt accountCheckingBatchTransOrderDetailBizMapperExt;
    @Autowired
    private AccountCheckingInvestOrderMapper accountCheckingInvestOrderMapper;
    @Autowired
    private AccountBaseMapperExt accountBaseMapperExt;
    @Autowired
    private BatchTransOrderDetailBizMapperExt batchTransOrderDetailBizMapperExt;
    @Autowired
    private BatchTransOrderDetailMapperExt batchTransOrderDetailMapperExt;
    @Autowired
    private RollbackRechargeOrderMapperExt rollbackRechargeOrderMapperExt;

    @Reference(version = "1.0.0")
    private RefundOrderDetailBizDubboService refundOrderDetailBizDubboService ;
    @Reference(version = "1.0.0")
    private ProjectLendDetailDubboService projectLendDetailDubboService;
    @Reference(version = "1.0.0")
    private CreditorTransferConfirmDubboService creditorTransferConfirmDubboService;

    @Override
    public List<AccountCheckingCommission> load(Long checkRecordId, int page, int pageSize) {
    	// shardingjdbc 强制走主库
		if (!HintManagerHolder.isMasterRouteOnly()) {
            HintManagerHolder.clear();
            HintManager hintManager = HintManager.getInstance();
            hintManager.setMasterRouteOnly();
        }

		log.debug("is matster route only : {}", HintManagerHolder.isMasterRouteOnly());

        AccountCheckingCommissionRequestDTO accountCheckingCommissionRequestDTO = new AccountCheckingCommissionRequestDTO();
        PageHelper.startPage(page, pageSize);
        accountCheckingCommissionRequestDTO.setStatus(Byte.valueOf("1"));
        accountCheckingCommissionRequestDTO.setCheckingRecordId(checkRecordId);
        List<AccountCheckingCommission> accountCheckingCommissionList = accountCheckingCommissionMapperExt.queryCheckingCommissionPage(accountCheckingCommissionRequestDTO);
        return accountCheckingCommissionList;
    }

    @Override
    public AccountCheckingException check(AccountCheckingCommission accountCheckingCommission, String checkDate) {
        AccountCheckingException accountCheckingException = new AccountCheckingException();
        List<String> errors = new ArrayList<String>();
        switch (accountCheckingCommission.getBusinessType()){
            case 02://提现 - 有实际业务比对
                compareToWithdraw(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
            case 03://投标
                compareToLoan(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
            case 04://还款 - 有实际业务比对
                compareToRepaymentNew(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
            case 05://债权
                compareToCreditor(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
            case 06://代偿
                compareToGuaranteeg(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
            case 8://充值
                /*compareToRecharge(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);*/
                log.info("Don't compare !");
                break;
            case 11://提现退回
                compareToRollBackWithdraw(accountCheckingCommission,accountCheckingException,errors,checkDate);
                break;
            default:
                notRegisterBusinessType(accountCheckingCommission,accountCheckingException,errors,checkDate);
                return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
        }
        return submit(accountCheckingCommission,accountCheckingException,errors,checkDate);
    }

    /**
     * 提现回退-比对
     */
    private void compareToRollBackWithdraw(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        String rollBackRequestNO = accountCheckingCommission.getRequestNo();
        RollbackRechargeOrder rollbackRechargeOrder = rollbackRechargeOrderMapperExt.selectByRequestNO(rollBackRequestNO);
        if( null == rollbackRechargeOrder ){
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        if( accountCheckingCommission.getAmount().compareTo(rollbackRechargeOrder.getRollbackFee()) !=0 ){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.ROLLBACK_WITHDRAW_NOT_EQUAL.getName());
            accountCheckingException.setPlatformRecordId(rollbackRechargeOrder.getId());
        }
    }

    private void compareToCreditor(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        CreditorTransferConfirmOrderDetailBizDTO creditorTransferConfirmOrderDetailBizDTO = creditorTransferConfirmDubboService.getConfirmOrderDetailBiz(accountCheckingCommission.getRequestNo(),BusinessTypeEnum.COMMISSION.getValue());
        if( null == creditorTransferConfirmOrderDetailBizDTO ){
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        CreditorTransferConfirmOrderDetailDTO creditorTransferConfirmOrderDetailDTO = creditorTransferConfirmDubboService.getConfirmOrderDetail(accountCheckingCommission.getRequestNo());

        if( accountCheckingCommission.getAmount().compareTo(creditorTransferConfirmOrderDetailBizDTO.getAmount()) != 0 ){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.CREDITOR_COMMISSION_AMOUNT_NOT_EQUAL.getName());
            accountCheckingException.setPlatformRecordId(creditorTransferConfirmOrderDetailDTO.getId());
        }

        if( !creditorTransferConfirmOrderDetailBizDTO.getSourcePlatformUserNo().equals(accountCheckingCommission.getSourceAccountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(creditorTransferConfirmOrderDetailDTO.getId());
        }
        if( !creditorTransferConfirmOrderDetailBizDTO.getTargetPlatformUserNo().equals(accountCheckingCommission.getTargetAcSoacountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(creditorTransferConfirmOrderDetailDTO.getId());
        }
        if( !String.valueOf(creditorTransferConfirmOrderDetailDTO.getProjectId()).equals(accountCheckingCommission.getProjectNo())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.PROJECT_NO_ERROR.getName());
            accountCheckingException.setPlatformRecordId(creditorTransferConfirmOrderDetailDTO.getId());
        }

    }

    /**
     * 存管没有注册的业务类型
     */
    private void notRegisterBusinessType(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        log.info("ShangHai bank has not register BusinessType !");
        accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
        errors.add(CheckResultEnum.BANK_NOT_REGISTER.getName());
    }
    /**
     * 比对提现
     */
    private void compareToWithdraw(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){

        WithdrawConfirmOrder withdrawConfirmOrder = accountCheckingWithdrawConfirmOrderMapperExt.queryWithdrawOrderByRequestNo(accountCheckingCommission.getRequestNo());
        WithdrawOrder withdrawOrder = null ;
        if ( null != withdrawConfirmOrder ){
            withdrawOrder = withdrawOrderMapperExt.selectByPrimaryKey(withdrawConfirmOrder.getWithdrawOrderId());
            if(null == withdrawOrder){
                log.error("提现订单没有id:{0}记录",withdrawConfirmOrder.getWithdrawOrderId());
                accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
                errors.add(CheckResultEnum.NO_RECORD.getName());
                return ;
            }
            validationWithdrawOrder(withdrawOrder,accountCheckingCommission,accountCheckingException,errors);

        }else{
            withdrawOrder = withdrawOrderMapperExt.queryWithdrawOrderByRequestNo(accountCheckingCommission.getRequestNo());
            if (null != withdrawOrder){
                validationWithdrawOrder(withdrawOrder,accountCheckingCommission,accountCheckingException,errors);
            }else{
                log.error("检索提现确认订单没有requestNO:{0}记录",accountCheckingCommission.getRequestNo());
                accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
                errors.add(CheckResultEnum.NO_RECORD.getName());
            }
        }
    }

    private void validationWithdrawOrder(WithdrawOrder withdrawOrder,AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors){
        if(withdrawOrder.getRealFee().compareTo(accountCheckingCommission.getAmount()) != 0){
            errors.add(CheckResultEnum.REAL_AMOUNT_NOT_EQUAL.getName());
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            accountCheckingException.setPlatformRecordId(withdrawOrder.getId());
        }
        //平台用户编号验证
        {
            AccountBase accountBaseOfSource = accountBaseMapperExt.selectByPrimaryKey(withdrawOrder.getAccountId());
            if( !accountCheckingCommission.getSourceAccountId().equals(accountBaseOfSource.getAccountNo())){
                errors.add(CheckResultEnum.PLATFORM_USER_NO_ERROR.getName());
                accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            }
        }
    }

    /**
     * 债权比对
     * @param accountCheckingCommission
     * @param accountCheckingException
     * @param errors
     */
    @SuppressWarnings("unused")
	private void compareToCreditor(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors){

    }

    /**
     * 比对充值
     */
    @SuppressWarnings("unused")
	private void compareToRecharge(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        RechargeOrder rechargeOrder = rechargeOrderMapperExt.queryRechargeOrderByRequestNo(accountCheckingCommission.getRequestNo());
        if( null == rechargeOrder ){
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        {
            log.info("Platform recharge has not service commission,ShangHai bank have record,Don't compare !");
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.PLATFORM_NOT_FUNCTION.getName());
        }

        //
    }

    /**
     * 代偿比对
     * 比对：
     *     佣金金额
     *     标的号
     * @param accountCheckingCommission
     * @param accountCheckingException
     * @param errors
     * @param checkDate
     */
    private void compareToGuaranteeg(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        RefundOrderDetailBizResponseDTO dto = refundOrderDetailBizDubboService.getDetailBizByRequestType(accountCheckingCommission.getRequestNo(),BusinessTypeEnum.COMMISSION.name().toString());
        if( null == dto ){
            accountCheckingException.setBusinessType(accountCheckingCommission.getBusinessType());
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        if( dto.getAmount().compareTo(accountCheckingCommission.getAmount()) != 0 ){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.COMMISSION_COMPENSATORY_AMOUNT_NOT_EQUAL.getName());
            accountCheckingException.setPlatformRecordId(dto.getId());
        }
    }

    /**
     * 还款比对(新版)
     * 兼容老版
     * @param accountCheckingCommission
     * @param accountCheckingException
     * @param errors
     */
    private void compareToRepaymentNew(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate) {
        accountCheckingCommission.setStatus(Byte.valueOf("2"));
        RefundOrderDetailBizResponseDTO dto = refundOrderDetailBizDubboService.getDetailBizByRequestType(accountCheckingCommission.getRequestNo(),BusinessTypeEnum.COMMISSION.name().toString());
        if( null == dto ){
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        if( dto.getAmount().compareTo(accountCheckingCommission.getAmount()) != 0 ){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.COMMISSION_REPAYMENT_AMOUNT_NOT_EQUAL.getName());
            accountCheckingException.setPlatformRecordId(dto.getId());
        }
        if( !dto.getSourcePlatformUserNo().equals(accountCheckingCommission.getSourceAccountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(dto.getId());
        }
        if( !dto.getTargetPlatformUserNo().equals(accountCheckingCommission.getTargetAcSoacountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(dto.getId());
        }
        if( !String.valueOf(dto.getProjectId()).equals(accountCheckingCommission.getProjectNo())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.PROJECT_NO_ERROR.getName());
            accountCheckingException.setPlatformRecordId(dto.getId());
        }

    }

    /**
     * 本方法在后续可以删除
     * @param batchTransOrderDetailBiz
     * @param accountCheckingException
     * @param errors
     * @param accountCheckingCommission
     */
    private void validationForRepayment(BatchTransOrderDetailBiz batchTransOrderDetailBiz,AccountCheckingException accountCheckingException,List<String> errors,AccountCheckingCommission accountCheckingCommission){
        if(!batchTransOrderDetailBiz.getSourceAccountNo().equals(accountCheckingCommission.getSourceAccountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(batchTransOrderDetailBiz.getId());
        }
        if(!batchTransOrderDetailBiz.getTargetAccountNo().equals(accountCheckingCommission.getTargetAcSoacountId())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.USER_ACCOUNT_ERROR.getName());
            accountCheckingException.setPlatformRecordId(batchTransOrderDetailBiz.getId());
        }

        BatchTransOrderDetail batchTransOrderDetail = batchTransOrderDetailMapperExt.selectByPrimaryKey(batchTransOrderDetailBiz.getTransDetailOrderId());
        if( !String.valueOf(batchTransOrderDetail.getProjectId()).equals(accountCheckingCommission.getProjectNo())){
            accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
            errors.add(CheckResultEnum.PROJECT_NO_ERROR.getName());
            accountCheckingException.setPlatformRecordId(batchTransOrderDetailBiz.getId());
        }

    }
    /**
     * 投标比对
     * @param accountCheckingCommission
     * @param accountCheckingException
     * @param errors
     */
	private void compareToLoan(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){

	    List<LendOrderDetailBizDTO> lendOrderDetailBizDTOS = projectLendDetailDubboService.queryLeanOrderDetailByRequestNO(accountCheckingCommission.getRequestNo(),BusinessTypeEnum.COMMISSION.getValue().toString());

        if ( null == lendOrderDetailBizDTOS || lendOrderDetailBizDTOS.isEmpty()){
            accountCheckingException.setHandleType(HandleTypeEnum.BACK_ONLY.getIndex());
            errors.add(CheckResultEnum.NO_RECORD.getName());
            return ;
        }
        log.info("lendOrderDetailDTOS:"+ JSON.toJSONString(lendOrderDetailBizDTOS));
        // 平台管理费一个流水号集，只有一条
        if(lendOrderDetailBizDTOS.size() == 1){
            LendOrderDetailDTO lendOrderDetailDTO = projectLendDetailDubboService.queryLendOrderDetailByRequestNO(accountCheckingCommission.getRequestNo());
            LendOrderDetailBizDTO detailBizDTO = lendOrderDetailBizDTOS.get(0);
            if(accountCheckingCommission.getAmount().compareTo(detailBizDTO.getAmount()) != 0 ){
                accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
                errors.add(CheckResultEnum.LOAN_MANAGEMENT_FEE_NOT_EQUAL.getName());
                accountCheckingException.setPlatformRecordId(lendOrderDetailDTO.getId());
            }
            if( !accountCheckingCommission.getSourceAccountId().equals(detailBizDTO.getSourcePlatformUserNo())){
                accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
                errors.add(CheckResultEnum.PLATFORM_USER_NO_ERROR.getName());
                accountCheckingException.setPlatformRecordId(lendOrderDetailDTO.getId());
            }
            if( !accountCheckingCommission.getTargetAcSoacountId().equals(detailBizDTO.getTargetPlatformUserNo())){
                accountCheckingException.setHandleType(HandleTypeEnum.BOTH_ERROR.getIndex());
                errors.add(CheckResultEnum.PLATFORM_USER_NO_ERROR.getName());
                accountCheckingException.setPlatformRecordId(lendOrderDetailDTO.getId());
            }
        }else{
            log.error("compare to loan:platform queryLendOrderDetailByRequestBizType more than the recode in compare to loan,requestNO:{}",accountCheckingCommission.getRequestNo());
            accountCheckingException.setHandleType(HandleTypeEnum.PT_MORE_THAN.getIndex());
            errors.add(CheckResultEnum.PT_MORE_THAN_RECODE.getName());
        }

    }


    private AccountCheckingException submit(AccountCheckingCommission accountCheckingCommission,AccountCheckingException accountCheckingException,List<String> errors,String checkDate){
        if( null != errors && errors.size() > 0 ){
            accountCheckingException.setStatus(Byte.valueOf("1"));
            accountCheckingException.setBusinessType(accountCheckingCommission.getBusinessType());
            accountCheckingException.setOrderNo(accountCheckingCommission.getOrderNo());
            accountCheckingException.setCheckingType(Byte.valueOf("4"));
            accountCheckingException.setCheckingRecordId(accountCheckingCommission.getCheckingRecordId());
            accountCheckingException.setCheckingDetailId(accountCheckingCommission.getId());
            //platformRecordId在之前逻辑中已处理
            accountCheckingException.setCreateTime(new Date());
            accountCheckingException.setBillDate(checkDate);       //这个字段需要改 VARCHAR，且参数由方法注动传入
            accountCheckingException.setDescription(errors.toString());
            accountCheckingCommission.setRemark(errors.toString());
            return accountCheckingException;
        }
        return null;
    }

    @Override
    public void batchUpdateCheckDetailStatus(Long checkRecordId, Byte status) {
        accountCheckingCommissionMapperExt.updateStatusByCheckingRecordId(checkRecordId,status);
    }

    @Override
    public AccountCheckingCommission parse(Long recordId, String content) {
        //1扣款时间2平台商编3订单号4业务类型5发起方平台用户编号6接收方平台用户编号7金额8币种9标的号10备注11请求流水号
        if (content == null || "".equals(content))
            return null;

        String[] sArr = content.split(",");
        AccountCheckingCommission record = new AccountCheckingCommission();
        record.setWithholdTime(DateUtil.parseT(sArr[0]));
        record.setPlatformMerchantNo(sArr[1]);
        record.setOrderNo(sArr[2]);
        record.setBusinessType(Byte.valueOf(sArr[3]));
        record.setSourceAccountId(sArr[4]);
        record.setTargetAcSoacountId(sArr[5]);
        record.setAmount(BigDecimal.valueOf(Double.valueOf(sArr[6])));
        record.setAmonnt("人民币"); //7-人民币
        record.setProjectNo(sArr[8]);
        record.setRemark(sArr[9]);
        record.setRequestNo(sArr[10]);

        record.setStatus((byte) 1); // 1待处理
        record.setCheckingRecordId(recordId);
        return record;
    }

    @Override
    public void save(List<AccountCheckingCommission> list) {
        if (list == null || list.isEmpty())
            return;
        //accountCheckingCommissionMapperExt.insertBatch(list);

        for(AccountCheckingCommission accountCheckingCommission : list){
            accountCheckingCommissionMapperExt.insert(accountCheckingCommission);
        }
    }

    @Override
    public void deleteCheckRecord(Long recordId) {
        accountCheckingCommissionMapperExt.deleteByCheckingRecordId(recordId);
    }

    @Override
    public void extendBusiness(Long checkRecordId) {
    	//暂无业务
    }

	@Override
	public void deleteAllCheckSuccessBankOrder(Long checkRecordId) {
        accountCheckingCommissionMapperExt.deleteByCheckingRecordId(checkRecordId);
	}
}
